package com.moyoutian.utils;

import java.util.Arrays;
import java.util.Random;
import java.util.function.Function;
import java.util.function.IntFunction;
import java.util.stream.IntStream;

/**
 * 数组工具类
 */
public class ArrayUtils {


    private static int getInt(int i) {
        return (int) Math.round(Math.random() * i);
    }

    /**
     * 获取一个int 数组
     *
     * @param l     数组长度
     * @param bound 随机数的最大值
     * @return int 数组
     */
    public static int[] getIntAr(int l, int bound) {
        return setRoundNumber(new int[l], bound);
    }

    /**
     * 获取一个 随机长度的随机数组int 数组
     *
     * @return int 数组
     */
    public static int[] getIntAr() {
        return getIntAr(1000, 100);
    }

    public static int[] setRoundNumber(int[] ints, int bound) {

        for (int i = 0; i < ints.length; i++) {
            ints[i] = getInt(bound);
        }
        return ints;
    }

    public static void printArray(int[] ints) {
        System.out.println("array:" + Arrays.toString(ints));
    }

    public static void printArray(String header, int[] ints) {
        System.out.println(header + "array:" + Arrays.toString(ints));
    }

    /**
     * 交换数组中的两个下标元素
     *
     * @param ints 数组
     * @param i    下标元素
     * @param j    下标元素
     */
    public static void swap(int[] ints, int i, int j) {
        int c = ints[i];
        ints[i] = ints[j];
        ints[j] = c;
    }


}
